#include <iostream>
using namespace std;
int a[1000];
void solve15(int n){
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int ans=0, tot;
    for(int color=(1<<n); color >= 0; color--){
        tot = 0;
        for(int i=0; i<n; i++){
            int j=i-1;
            while(j>=0 && bool(color&(1<<i)) != bool(color&(1<<j))) j--;
            if(j>=0 && a[i]==a[j])
                tot += a[i];
        }
        ans = max(ans, tot);
    }
    cout << ans << '\n';
}
void solve(){
    int n;
    cin >> n;
    if(n <= 15)
        solve15(n);
    else
        cout << "0\n";
}
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    for(int i=0; i<t; i++)
        solve();
    
    return 0;
}